﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using CRMBiz;

namespace CRMWeb.WebServices
{
    /// <summary>
    /// Summary description for InsertCombineApplicantData
    /// </summary>
    public class InsertCombineApplicantData : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            try
            {

                int app_id = int.Parse(context.Request.Params["app_id"]);
                int contactID = 0;
                int c_app_id = int.Parse(context.Request.Params["c_app_id"]);
                string combineAppId = context.Request.Params["combineAppId"];
                int noInApplication = 0;
                string[] split = context.Request.Params["contactID"].Split(',');
                bool combineApp = false;
                if (context.Request.Params["contactID"] != null)
                {
                    for (int i = 0; i < split.Length; i++)
                    {
                        if (split[i] != null && split[i].ToString().Trim() != "")
                        {
                            if (split[i].Split('_')[0] != null)
                            {
                                contactID = Convert.ToInt32(split[i].Split('_')[0].ToString());
                            }

                            for (int j = 0; j < split.Length; j++)
                            {
                                if (split[j] != null && split[j].ToString().Trim() != "")
                                {
                                    if (split[j].Split('_')[1].ToString() == "0")
                                    {
                                        noInApplication = 0;
                                        combineApp = true;
                                    }
                                }
                            }
                            if (split[i].Split('_')[1] != null && combineApp == false)
                            {
                                noInApplication = Convert.ToInt32(split[i].Split('_')[1].ToString());

                            }

                            for (int k = 0; k < split.Length; k++)
                            {
                                if (split[k] != null && split[k].ToString().Trim() != "")
                                {
                                    combineAppId = split[i].Split('_')[2].ToString();
                                }
                            }


                            string Msg = ClientProfileHandler.InsertCombineApplicantData(app_id, contactID, c_app_id, combineAppId, noInApplication);
                            context.Response.Write(Msg);
                        }
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}